﻿import com.kirillam.handy.core.HATObject;
import com.kirillam.handy.datastructures.WeakReference;
import com.kirillam.handy.events.HATEvent;


/**
* Clip to attach other necessary clips to. Also sends HATEvent.ENTER_FRAME events.
*/

class com.kirillam.handy.core.HATControlClip extends HATObject
{
	private static var _instance	: HATControlClip;
	
	/** Single instance of the class. */
	public static function get instance() : HATControlClip
	{
		if ( _instance == null ) {
			_instance	= new HATControlClip();
		}
		
		return _instance;
	}
	
	
	/** Single instance of the class. */
	public static function get clip() : MovieClip
	{
		if ( _instance == null ) {
			_instance	= new HATControlClip();
		}
		
		return _instance._clip;
	}
	
	
	
	var _clip	: MovieClip;
	
	
	public function HATControlClip() 
	{
		super();
		
		var depth	: Number	= -1;
		while ( _root.getInstanceAtDepth( depth ) != null ) {
			depth--;
		}
		
		_clip					= _root.createEmptyMovieClip( "__hat_clip__", depth );
		
		var self	: MovieClip	= this;
		_clip.onEnterFrame		= function()
		{
			self.onFrameEntered();
		}
		
		_global.ASSetPropFlags( _root, "__hat_clip__" , 7, true );
	}
	
	
	/* Called by the beacon clip */
	
	private function onFrameEntered()
	{
		sendEvent( new HATEvent( HATEvent.ENTER_FRAME ) );
		sendEvent( new HATEvent( HATEvent.RENDER ) );
		WeakReference.onAboutToRender();
	}
}